﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductCommandHandler
{
    public class ProductDeleteCommandHandler : IRequestHandler<ProductDeleteCommand, int>
    {
        private readonly IProductRepository _productRepository;

        public ProductDeleteCommandHandler(IProductRepository productRepository)
        {
            _productRepository = productRepository;
        }
        /// <summary>
        /// 产品管理逻辑删除（单删）
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProductDeleteCommand request, CancellationToken cancellationToken)
        {
            var list= await _productRepository.FindById(request.ProductId);
            list.IsDelete = true;
            list.DeleteTime = DateTime.Now;
            list.DeleteName = "admin";
            return await _productRepository.Update(list);
        }
    }
}
